﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            float sum = 0;
            float count = 0;
            bool flag = true;
            Console.WriteLine("请输入学生数：");
            int a = int.Parse(Console.ReadLine());
            while (flag)
            {
                try
                {

                    Console.WriteLine("请输入考试成绩：");
                    float score = float.Parse(Console.ReadLine());
                    sum += score;

                    count++;
                }
                catch (FormatException)
                {
                    Console.WriteLine("异常已处理");
                }
                catch (OverflowException)
                {
                    Console.WriteLine("异常已处理");
                }
                catch (Exception)
                {

                    throw;
                }
                finally
                {
                    if (count == a)
                    {
                        flag = false;
                        Console.WriteLine($"总学生数为：{count}");
                        Console.WriteLine($"总成绩为：{sum}");
                        Console.WriteLine($"平均分为：{sum / count}");
                    }
                }
            }


            Test01();
        }
       
        public static void Test01()
        {
            //存放在银行账户中的余额
            double a = 100000000.00;
            //用户想要从银行账户中提取的金额
            double b = 0;
            Boolean f = false;
            Boolean p = true;
            while (p)
            {
                Console.WriteLine("请选择功能：1、存款，2、取款 3、退出");
                int key = int.Parse(Console.ReadLine());
                switch (key)
                {
                    case 1:
                        Console.WriteLine("请输入存款的金额");
                        try
                        {
                            double c = double.Parse(Console.ReadLine());
                            a += c;
                        }
                        catch (FormatException e)
                        {
                            Console.WriteLine(e.Message);
                            Console.WriteLine(e.Source);
                            Console.WriteLine(e.StackTrace);
                            f = true;
                        }
                        Boolean o = true;
                        while (o)
                        {
                            o = false;
                            if (f)
                            {
                                f = false;
                                Console.WriteLine();
                                Console.WriteLine("请输入重新存款的金额");
                                try
                                {
                                    double c = double.Parse(Console.ReadLine());
                                    a += c;
                                }
                                catch (FormatException e)
                                {
                                    Console.WriteLine(e.Message);
                                    Console.WriteLine(e.Source);
                                    Console.WriteLine(e.StackTrace);
                                    f = true;
                                    o = true;
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.Message);
                                    Console.WriteLine(e.Source);
                                    Console.WriteLine(e.StackTrace);
                                    f = true;
                                    o = true;
                                }
                            }
                            else
                            {
                                Console.WriteLine("余额为{0}", a);
                            }
                        }


                        break;
                    case 2:
                        Console.WriteLine("请输入取款的金额");
                        try
                        {
                            b = double.Parse(Console.ReadLine());
                            if (b > a)
                            {
                                throw new ArgumentOutOfRangeException();
                            }
                        }
                        catch (OverflowException e)
                        {
                            Console.WriteLine(e.Message);
                            Console.WriteLine(e.Source);
                            Console.WriteLine(e.StackTrace);
                            f = true;
                        }
                        Boolean l = true;
                        while (l)
                        {
                            l = false;
                            if (f)
                            {
                                f = false;
                                Console.WriteLine();
                                Console.WriteLine("请重新输入取款的金额");
                                try
                                {
                                    b = double.Parse(Console.ReadLine());
                                    if (b > a)
                                    {
                                        throw new ArgumentOutOfRangeException();
                                    }
                                }
                                catch (OverflowException e)
                                {
                                    Console.WriteLine(e.Message);
                                    Console.WriteLine(e.Source);
                                    Console.WriteLine(e.StackTrace);
                                    f = true;
                                    l = true;
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.Message);
                                    Console.WriteLine(e.Source);
                                    Console.WriteLine(e.StackTrace);
                                    f = true;
                                    l = true;
                                }
                            }
                            else
                            {
                                a = a - b;
                                Console.WriteLine("余额为{0}", a);
                            }
                        }
                        break;
                    case 3:
                        p = false;
                        break;
                    default:
                        Console.WriteLine("输入错误，请重新输入");
                        break;
                }
            }
        }
    }
}
